// pages/myList/myList.js
const app = getApp();
const util = require("../../utils/util")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    finishedlist: null,
    unfinishedlist: null
  },

  getListInfo(res){
    //查询此订单的详细信息，将id封装成对象给后端
    console.log(res.currentTarget.dataset.getinfolistid)
    wx.request({
      
      url: util.BASE_URL+'/get/getlistinfo',
      method: 'POST',
      data:{
        id: res.currentTarget.dataset.getinfolistid
      },
      success(res){
        console.log(res.data)
        app.globalData.listInfo = res.data
      }
    })

    wx.showLoading({
      title: '加载中',
    })
    setTimeout(function () {
      wx.hideLoading(),
      wx.navigateTo({
        url: '/pages/listInfo/listInfo',
      })
    }, 200)
    //延时200ms否则小程序没有将订单信息获取到
  },

  onShow: function () {
    //通过用户信息读取该用户名下的所有订单
    var that = this 
    wx.request({
      url: util.BASE_URL + '/get/unfinishedlist',
      method: "POST",
      data : app.globalData.userInfo,
      success(res){
        that.setData({
          unfinishedlist: res.data
        })
      },
      fail(err){
        console.log('Fail'+err)
      }
    })
    wx.request({
      url: util.BASE_URL + '/get/finishedlist',
      method: "POST",
      data : app.globalData.userInfo,
      success(res){
        that.setData({
          finishedlist: res.data
        })
      },
      fail(err){
        console.log('Fail'+err)
      }
    })
  }
})